<template>
	<view class="text-df">
		<view class="flex-row-bt padding-lg bg-white">
			<view class="flex-row">
				<u-avatar :text="userInfo.name.slice(0,1)" font-size="20" :random-bg-color="true" size="60"></u-avatar>
				<view v-if="isLogin" class="margin-left-sm text-lg" style="line-height: 120rpx;">{{userInfo.name}}
				</view>
				<view v-else class="margin-left-sm text-lg" style="line-height: 120rpx;" @click="toLogin">
					{{userInfo.name}}
				</view>
			</view>
			<view style="text-align: center;">
				<uni-icons type="gift" size="20" color="#aaaaaa"></uni-icons>
				<view class="text-xs text-low">积分: 0</view>
			</view>
		</view>

		<view class="">

			<view class="bg-white margin-top-sm text-sm">
				<view class="flex-row-bt padding-lr-sm " style="height: 90rpx;line-height: 90rpx;" @tap="uplode">
					<view class="flex-row">
						<uni-icons type="upload" size="20" color="#aaaaaa"></uni-icons>
						<view class="margin-left-xs text-df" style="">我的上报</view>
					</view>
					<u-icon name="arrow-right" color="#aaaaaa" size="16"></u-icon>
				</view>
				<u-line></u-line>
				<view class="flex-row-bt padding-lr-sm " style="height: 90rpx;line-height: 90rpx;" @click="to_myWork">
					<view class="flex-row">
						<uni-icons type="list" size="20" color="#aaaaaa"></uni-icons>
						<view class="margin-left-xs text-df">我的任务</view>
					</view>
					<u-icon name="arrow-right" color="#aaaaaa" size="16"></u-icon>
				</view>
				<u-line></u-line>
				<view class="flex-row-bt padding-lr-sm " style="height: 90rpx;line-height: 90rpx;">
					<view class="flex-row">
						<u-icon name="order" color="#aaaaaa" size="20"></u-icon>
						<view class="margin-left-xs text-df">我的订单</view>
					</view>
					<u-icon name="arrow-right" color="#aaaaaa" size="16"></u-icon>
				</view>
				<u-line></u-line>
				<view class="flex-row-bt padding-lr-sm " style="height: 90rpx;line-height: 90rpx;">
					<view class="flex-row">
						<uni-icons type="compose" size="20" color="#aaaaaa"></uni-icons>
						<view class="margin-left-xs text-df" style="">意见反馈</view>
					</view>
					<u-icon name="arrow-right" color="#aaaaaa" size="16"></u-icon>
				</view>
			</view>

			<view class="flex-row-bt padding-lr-sm margin-top-sm bg-white  text-df" style="height: 90rpx;line-height: 90rpx;" @click="exit_login">
				<view class="flex-row">
					<u-icon name="setting" color="#aaa " size="18"></u-icon>
					<view class="margin-left-xs text-df">退出登录</view>
				</view>
				<u-icon name="arrow-right" color="#aaaaaa" size="16"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: 'https://ts1.cn.mm.bing.net/th/id/R-C.553a026a6341c26c3e7199747d13abbe?rik=qPZiiEQMTuNGww&riu=http%3a%2f%2fimg95.699pic.com%2fphoto%2f40012%2f6770.jpg_wh860.jpg&ehk=1tVr%2bLg7IIrXNt0D1IhNSaChefFQdT%2b1%2byehk4jvDsA%3d&risl=&pid=ImgRaw&r=0',
				// 是否登录
				isLogin: false,
				userInfo: {
					id: null,
					phone: "18296898672",
					"name": "未登录...",
					"address": "",
					"authority": "0",
					"openId": null,
					"addressList": [],
				}
			}
		},
		onShow() {
			this.isLogin = uni.getStorageSync('isLogin')
			if (this.isLogin) {
				this.userInfo = uni.getStorageSync('userInfo')
			}
		},
		methods: {
			toLogin() {
				uni.navigateTo({
					url: '/pages/login'
				})
			},
			uplode(){
				uni.navigateTo({
					url:'/pages/myRelease/myRelease'
				})
			},
			// 退出登录
			exit_login() {
				uni.removeStorageSync('code')
				if (this.isLogin) {
					uni.clearStorage();
					uni.showToast({
						title: '退出成功',
						icon: 'none'
					});
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages/login'
						})
					}, 1000)
				} else {
					//登录提示
					this.loginTip()
				}
			},

			//登录提示
			loginTip() {
				uni.showModal({
					title: '登录提示',
					content: '您还未登录，是否跳转登录界面？',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}
					}
				})
			},

			// 跳转我的任务
			to_myWork() {
				if (this.isLogin) {
					uni.switchTab({
						url: '/pages/mine/work/index'
					})
				} else {
					//登录提示
					this.loginTip()
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f7f7f7;
	}
</style>